import axios, { AxiosError, AxiosResponse } from 'axios';

interface ErrorResponse {
  error?: string;
}

const request = axios.create({
  baseURL: 'http://127.0.0.1:3000',
  timeout: 100000
});

// 响应拦截器
request.interceptors.response.use(
  (response: AxiosResponse) => response.data,
  (error: AxiosError<ErrorResponse>) => {
    const message = error.response?.data?.error || '请求失败';
    return Promise.reject(message);
  }
);

export default request;